package com.ruoyi.material.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.MaterialEnvMonitor;
import com.ruoyi.material.service.IMaterialEnvMonitorService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊材库环境监测Controller
 * 
 * @author ruoyi
 * @date 2023-02-11
 */
@Controller
@RequestMapping("/material/monitor")
public class MaterialEnvMonitorController extends BaseController
{
    private String prefix = "material/monitor";

    @Autowired
    private IMaterialEnvMonitorService materialEnvMonitorService;

    @RequiresPermissions("material:monitor:view")
    @GetMapping()
    public String monitor()
    {
        return prefix + "/monitor";
    }

    @GetMapping("/dynamic")
    public String dynamic() {
        return prefix + "/dynamic";
    }

    /**
     * 查询焊材库环境监测列表
     */
    @RequiresPermissions("material:monitor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaterialEnvMonitor materialEnvMonitor)
    {
        startPage();
        List<MaterialEnvMonitor> list = materialEnvMonitorService.selectMaterialEnvMonitorList(materialEnvMonitor);
        return getDataTable(list);
    }

    /**
     * 导出焊材库环境监测列表
     */
    @RequiresPermissions("material:monitor:export")
    @Log(title = "焊材库环境监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaterialEnvMonitor materialEnvMonitor)
    {
        List<MaterialEnvMonitor> list = materialEnvMonitorService.selectMaterialEnvMonitorList(materialEnvMonitor);
        ExcelUtil<MaterialEnvMonitor> util = new ExcelUtil<MaterialEnvMonitor>(MaterialEnvMonitor.class);
        return util.exportExcel(list, "焊材库环境监测数据");
    }

    /**
     * 新增焊材库环境监测
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊材库环境监测
     */
    @RequiresPermissions("material:monitor:add")
    @Log(title = "焊材库环境监测", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaterialEnvMonitor materialEnvMonitor)
    {
        return toAjax(materialEnvMonitorService.insertMaterialEnvMonitor(materialEnvMonitor));
    }

    /**
     * 修改焊材库环境监测
     */
    @RequiresPermissions("material:monitor:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MaterialEnvMonitor materialEnvMonitor = materialEnvMonitorService.selectMaterialEnvMonitorById(id);
        mmap.put("materialEnvMonitor", materialEnvMonitor);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊材库环境监测
     */
    @RequiresPermissions("material:monitor:edit")
    @Log(title = "焊材库环境监测", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaterialEnvMonitor materialEnvMonitor)
    {
        return toAjax(materialEnvMonitorService.updateMaterialEnvMonitor(materialEnvMonitor));
    }

    /**
     * 删除焊材库环境监测
     */
    @RequiresPermissions("material:monitor:remove")
    @Log(title = "焊材库环境监测", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(materialEnvMonitorService.deleteMaterialEnvMonitorByIds(ids));
    }
}
